
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

/**
 * @author cheng
 * @date 2021/10/8 21:44
 */
public class HadoopCase {
    public static void main(String[] args){
        try{
            System.setProperty("hadoop.home.dir","D:\\code\\hadoop-2.7.3");
            System.setProperty("HADOOP_USER_NAME","root");

            String fileName = "/test";
            Configuration conf = new Configuration();
            conf.set("fs.defaultFS", "hdfs://192.168.9.11:9000");  // 这里根据自己实际情况调整
            conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
            FileSystem fs = FileSystem.get(conf);
            if(fs.exists(new Path(fileName))){
                System.out.println("文件存在");
            }else{
                System.out.println("文件不存在");
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
